#pragma once

#include "effectbase.h"
#include <osg\Vec4>
#include <osg\NodeCallback>
#include <osgUtil\CullVisitor>
#include <osg\PositionAttitudeTransform>
#include <osg/Switch>
#include "transformableactor.h"

namespace VrDataCore
{
	class VRDATACORE_EXPORT ParticleEffect:public EffectBase
	{
	public:
		ParticleEffect(void);
	protected:
		virtual ~ParticleEffect(void);
		void showParticle();
		void hideParticle();
	public:
		void setNodeFile(QString file);
		QString getNodeFile();
		void setTextureFile(QString file);
		QString getTextureFile();
		void setTranslation(osg::Vec3 translation);
		osg::Vec3 getTranslation();
		void setRotation(osg::Vec3 rota);
		osg::Vec3 getRotation();
		virtual void apply(CoreBase::ActorBase* bindingactor);
		virtual void unApply(CoreBase::ActorBase* bindingactor);
		virtual void buildPropertyMap();
		void update(const osg::Vec3& eye);
	private:
		QString												_nodeFileName;
		QString												_textureFileName;
		osg::Vec3											_rotation;
		osg::Vec3											_translation;
		osg::ref_ptr<osg::PositionAttitudeTransform>		_particleNode;
		osg::Node*											_node;
	};

	class ParticleEffectCallback: public osg::NodeCallback
	{
	public:
		ParticleEffectCallback(ParticleEffect* pe)
		{
			_pe = pe;
		}
		virtual void operator()(osg::Node* node, osg::NodeVisitor* nv)
		{
			if(nv->getVisitorType() == osg::NodeVisitor::CULL_VISITOR )
			{
				osg::Vec3 eye,centre,up;
				osgUtil::CullVisitor* cv = static_cast<osgUtil::CullVisitor*>(nv);
				cv->getRenderStage()->getCamera()->getViewMatrixAsLookAt(eye,centre,up);
				_pe->update(eye);
			}
			traverse(node, nv); 
		}
		~ParticleEffectCallback(){}
		private:
			ParticleEffect*								_pe;
	};
}